package com.jiang.daily.Q2273;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/10/13 10:49
 */
class Solution {
    public List<String> removeAnagrams(String[] words) {
        List<String> res = new ArrayList<>();
        res.add(words[0]);

        for (int i = 1; i < words.length; i++) {
            if (!compare(words[i], words[i - 1])) {
                res.add(words[i]);
            }
        }

        return res;
    }

    private boolean compare(String s1, String s2) {
        int[] arr = new int[26];

        for (char c : s1.toCharArray()) {
            arr[c - 'a']++;
        }

        for (char c : s2.toCharArray()) {
            arr[c - 'a']--;
        }

        for (int v: arr) {
            if (v != 0) return false;
        }

        return true;
    }
}
